/*
 * HubEntryFetcher.java
 *
 * Created on 27 November 2006, 23:08
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hubsniffer.hublist.db;

import hubsniffer.db.DataBaseManager;
import libjdc.hublist.HubEntry;
import libjdc.hublist.HublistEntry;
import libjdc.hublist.XMLHublistWriter;
import hubsniffer.util.Host;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.TreeSet;

/**
 *
 * @author root
 */
public class HubEntryFetcher {
    
    private DataBaseManager db;
    
    /** Creates a new instance of HublistReader */
    public HubEntryFetcher(DataBaseManager db) {
        this.db = db;
    }
    
    public TreeSet<HubEntry> getAll() throws SQLException, UnsupportedEncodingException{
        TreeSet<HubEntry> all =new TreeSet<HubEntry>();
        
        String query = "SELECT * FROM hub_entry";
        ResultSet res = db.writeQuery(query);
        while(res.next()){
            if(
                    res.getInt("users") != 20000 &&
                    res.getInt("users") > 0 &&
                    !Host.isIP(res.getString("address"))
                    )
            {
                HubEntry current = new HubEntry(
                        res.getString("name"),
                        res.getString("address").toLowerCase(),
                        res.getString("description"),
                        res.getInt("users"),
                        res.getString("country"),
                        res.getString("shared"),
                        res.getString("status"),
                        res.getString("min_share"),
                        res.getString("min_slots"),
                        res.getString("max_hubs"),
                        res.getString("max_users"),
                        res.getString("reliability"),
                        res.getString("rating"),
                        res.getString("port")
                        );
                
                all.add(current);
            }
        }
        return all;
    }

}
